bitkeeper revision 1.1062.1.8 (40f2b4a7XA6Vy0Lq6nLBErX9_qDhcQ)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Mon, 12 Jul 2004 15:56:23 +0000 (15:56 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Mon, 12 Jul 2004 15:56:23 +0000 (15:56 +0000)
Various cleanups, and fix a domain-destruct bug that left GDT
references hanging.

19 files changed:
.rootkeys
xen/arch/x86/dom0_ops.c
xen/arch/x86/domain.c
xen/arch/x86/memory.c
xen/arch/x86/shadow.c
xen/arch/x86/traps.c
xen/arch/x86/x86_32/mm.c
xen/common/dom0_ops.c
xen/common/domain.c
xen/common/elf.c [new file with mode: 0644]
xen/common/kernel.c
xen/include/asm-x86/domain.h [new file with mode: 0644]
xen/include/asm-x86/mm.h
xen/include/asm-x86/processor.h
xen/include/asm-x86/shadow.h
xen/include/xen/elf.h
xen/include/xen/mm.h
xen/include/xen/sched.h
xen/include/xen/shadow.h [deleted file]

index 7a325644bd620c968772c0691d45541ff0993ed1..b99af7d0b02d7af063beb3febece5685ed2cf526 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 3ddb79bdLX_P6iB7ILiblRLWvebapg xen/common/dom0_ops.c
 3e6377e4i0c9GtKN65e99OtRbw3AZw xen/common/dom_mem_ops.c
 3ddb79bdYO5D8Av12NHqPeSviav7cg xen/common/domain.c
+40f2b4a27xPOh3R6zD4M_aabz-TDyg xen/common/elf.c
 3fba5b96H0khoxNiKbjdi0inpXV-Pw xen/common/event_channel.c
 3ddb79bd9drcFPVxd4w2GPOIjLlXpA xen/common/kernel.c
 3e4cd9d8LAAghUY0hNIK72uc2ch_Nw xen/common/keyhandler.c
 3ddb79c3r9-31dIsewPV3P3i8HALsQ xen/include/asm-x86/delay.h
 3ddb79c34BFiXjBJ_cCKB0aCsV1IDw xen/include/asm-x86/desc.h
 40715b2dTokMLYGSuD58BnxOqyWVew xen/include/asm-x86/div64.h
+40f2b4a2hC3HtChu-ArD8LyojxWMjg xen/include/asm-x86/domain.h
 3e20b82fl1jmQiKdLy7fxMcutfpjWA xen/include/asm-x86/domain_page.h
 3ddb79c3NU8Zy40OTrq3D-i30Y3t4A xen/include/asm-x86/fixmap.h
 3e2d29944GI24gf7vOP_7x8EyuqxeA xen/include/asm-x86/flushtlb.h
 40589969nPq3DMzv24RDb5LXE9brHw xen/include/xen/sched-if.h
 3ddb79c0LzqqS0LhAQ50ekgj4oGl7Q xen/include/xen/sched.h
 403a06a7H0hpHcKpAiDe5BPnaXWTlA xen/include/xen/serial.h
-40e3392dib7GrcBAu5cT-EUZTYzeEQ xen/include/xen/shadow.h
 3ddb79c14dXIhP7C2ahnoD08K90G_w xen/include/xen/slab.h
 3ddb79c09xbS-xxfKxuV3JETIhBzmg xen/include/xen/smp.h
 3ddb79c1Vi5VleJAOKHAlY0G2zAsgw xen/include/xen/softirq.h
index 4ee83fb6ad443812184851a3488dedd883793f38..5df4c568b471c4cdc44dcaf83dfa3435b28a092f 100644 (file)
@@ -18,7 +18,7 @@
 #include <asm/pdb.h>
 #include <xen/trace.h>
 #include <xen/console.h>
-#include <xen/shadow.h>
+#include <asm/shadow.h>
 #include <hypervisor-ifs/sched_ctl.h>
 
 #define TRC_DOM0OP_ENTER_BASE  0x00020000
index fcc1c75ecc6844e5d1621ffffa39a02f420d256c..5d8fd069803a1e544550acbee20bb00cc8c0698b 100644 (file)
@@ -1,3 +1,9 @@
+/******************************************************************************
+ * arch/x86/domain.c
+ * 
+ * x86-specific domain handling (e.g., register setup and context switching).
+ */
+
 /*
  *  Copyright (C) 1995  Linus Torvalds
  *
 #include <asm/ldt.h>
 #include <xen/irq.h>
 #include <xen/event.h>
-#include <xen/shadow.h>
+#include <asm/shadow.h>
 #include <xen/console.h>
-
 #include <xen/elf.h>
 
-extern int loadelfimage(char *);
-extern int readelfimage_base_and_size(char *, unsigned long,
-                  unsigned long *, unsigned long *, unsigned long *);
-
 #if !defined(CONFIG_X86_64BITMODE)
 /* No ring-3 access in initial page tables. */
 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
@@ -46,7 +47,6 @@ extern int readelfimage_base_and_size(char *, unsigned long,
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
 
-
 int hlt_counter;
 
 void disable_hlt(void)
@@ -207,12 +207,6 @@ void machine_power_off(void)
     machine_restart(0);
 }
 
-/* this belongs in include/asm, but there doesn't seem to be a suitable place */
-void free_perdomain_pt(struct domain *d)
-{
-    free_page((unsigned long)d->mm.perdomain_pt);
-}
-
 void arch_do_createdomain(struct domain *d)
 {
     d->shared_info = (void *)get_free_page();
@@ -459,14 +453,19 @@ void domain_relinquish_memory(struct domain *d)
         write_ptbase(&current->mm);
 
     /* Exit shadow mode before deconstructing final guest page table. */
-    if ( shadow_mode(d) )
-        shadow_mode_disable(d);
+    shadow_mode_disable(d);
 
     /* Drop the in-use reference to the page-table base. */
     if ( pagetable_val(d->mm.pagetable) != 0 )
         put_page_and_type(&frame_table[pagetable_val(d->mm.pagetable) >>
                                       PAGE_SHIFT]);
 
+    /*
+     * Relinquish GDT mappings. No need for explicit unmapping of the LDT as 
+     * it automatically gets squashed when the guest's mappings go away.
+     */
+    destroy_gdt(d);
+
     /* Relinquish Xen-heap pages. Currently this can only be 'shared_info'. */
     page = virt_to_page(d->shared_info);
     if ( test_and_clear_bit(_PGC_allocated, &page->count_and_flags) )
index 861bad533f369bb03355855e27270cd063e69b14..a2cef38ed29f3856ef16e721e779e89d8ae56baf 100644 (file)
@@ -91,7 +91,7 @@
 #include <xen/errno.h>
 #include <xen/perfc.h>
 #include <xen/irq.h>
-#include <xen/shadow.h>
+#include <asm/shadow.h>
 #include <asm/page.h>
 #include <asm/flushtlb.h>
 #include <asm/io.h>
index dc08bd0199d85ff048e281d7d342c22de100dde4..a611f93c4216fb5b375a1bf6c4f9e2dff2a59cc4 100644 (file)
@@ -3,7 +3,7 @@
 #include <xen/config.h>
 #include <xen/types.h>
 #include <xen/mm.h>
-#include <xen/shadow.h>
+#include <asm/shadow.h>
 #include <asm/domain_page.h>
 #include <asm/page.h>
 #include <xen/event.h>
@@ -295,29 +295,30 @@ nomem:
     return -ENOMEM;
 }
 
-void shadow_mode_disable( struct domain *p )
+void __shadow_mode_disable(struct domain *d)
 {
-    struct mm_struct *m = &p->mm;
+    struct mm_struct *m = &d->mm;
     struct shadow_status *next;
 
-    __free_shadow_table( m );
+    __free_shadow_table(m);
     m->shadow_mode = 0;
 
     SH_LOG("freed tables count=%d l1=%d l2=%d",
-           m->shadow_page_count, perfc_value(shadow_l1_pages), perfc_value(shadow_l2_pages));
+           m->shadow_page_count, perfc_value(shadow_l1_pages), 
+           perfc_value(shadow_l2_pages));
 
     next = m->shadow_ht_extras;
-    while( next )
+    while ( next )
     {
         struct shadow_status * this = next;
         m->shadow_extras_count--;
         next = *((struct shadow_status **)(&next[shadow_ht_extra_size]));
-        kfree( this );
+        kfree(this);
     }
 
     SH_LOG("freed extras, now %d", m->shadow_extras_count);
 
-    if( m->shadow_dirty_bitmap  )
+    if ( m->shadow_dirty_bitmap  )
     {
         kfree( m->shadow_dirty_bitmap );
         m->shadow_dirty_bitmap = 0;
@@ -475,53 +476,51 @@ out:
     return rc;
 }
 
-int shadow_mode_control( struct domain *p, dom0_shadow_control_t *sc )
+int shadow_mode_control(struct domain *d, dom0_shadow_control_t *sc)
 {
     unsigned int cmd = sc->op;
     int rc = 0;
 
-    spin_lock(&p->mm.shadow_lock);
+    spin_lock(&d->mm.shadow_lock);
 
-    if ( p->mm.shadow_mode && cmd == DOM0_SHADOW_CONTROL_OP_OFF )
+    if ( cmd == DOM0_SHADOW_CONTROL_OP_OFF )
     {
-        shadow_mode_disable(p);
+        shadow_mode_disable(d);
     }
     else if ( cmd == DOM0_SHADOW_CONTROL_OP_ENABLE_TEST )
     {
-        if(p->mm.shadow_mode) shadow_mode_disable(p);
-        shadow_mode_enable(p, SHM_test);
+        shadow_mode_disable(d);
+        shadow_mode_enable(d, SHM_test);
     } 
     else if ( cmd == DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY )
     {
-        if(p->mm.shadow_mode) shadow_mode_disable(p);
-        shadow_mode_enable(p, SHM_logdirty);
+        shadow_mode_disable(d);
+        shadow_mode_enable(d, SHM_logdirty);
     } 
-    else if ( p->mm.shadow_mode && cmd >= DOM0_SHADOW_CONTROL_OP_FLUSH && cmd<=DOM0_SHADOW_CONTROL_OP_CLEAN2 )
+    else if ( shadow_mode(d) && 
+              (cmd >= DOM0_SHADOW_CONTROL_OP_FLUSH) && 
+              (cmd <= DOM0_SHADOW_CONTROL_OP_CLEAN2) )
     {
-        rc = shadow_mode_table_op(p, sc);
+        rc = shadow_mode_table_op(d, sc);
     }
     else
     {
         rc = -EINVAL;
     }
 
-       flush_tlb_cpu(p->processor);
+       flush_tlb_cpu(d->processor);
    
-    spin_unlock(&p->mm.shadow_lock);
+    spin_unlock(&d->mm.shadow_lock);
 
     return rc;
 }
 
-
-
-static inline struct pfn_info *alloc_shadow_page( struct mm_struct *m )
+static inline struct pfn_info *alloc_shadow_page(struct mm_struct *m)
 {
     m->shadow_page_count++;
-
-    return alloc_domain_page( NULL );
+    return alloc_domain_page(NULL);
 }
 
-
 void unshadow_table( unsigned long gpfn, unsigned int type )
 {
     unsigned long spfn;
index c43aafea23822b625f251b93153d8ee961a354fa..aa74ae4dfe5001564f702ec8bb69d6f091aa8cbc 100644 (file)
@@ -38,7 +38,7 @@
 #include <xen/spinlock.h>
 #include <xen/irq.h>
 #include <xen/perfc.h>
-#include <xen/shadow.h>
+#include <asm/shadow.h>
 #include <asm/domain_page.h>
 #include <asm/system.h>
 #include <asm/io.h>
index 59e304e4a77574128f96dc8129d6aab1378a7a28..d034240b4129af7b0de7bbc6de408245357bcf4e 100644 (file)
@@ -212,13 +212,26 @@ int check_descriptor(unsigned long a, unsigned long b)
 }
 
 
-long set_gdt(struct domain *p, 
+void destroy_gdt(struct domain *d)
+{
+    int i;
+    unsigned long pfn;
+
+    for ( i = 0; i < 16; i++ )
+    {
+        if ( (pfn = l1_pgentry_to_pagenr(d->mm.perdomain_pt[i])) != 0 )
+            put_page_and_type(&frame_table[pfn]);
+        d->mm.perdomain_pt[i] = mk_l1_pgentry(0);
+    }
+}
+
+
+long set_gdt(struct domain *d, 
              unsigned long *frames,
              unsigned int entries)
 {
     /* NB. There are 512 8-byte entries per GDT page. */
     int i, nr_pages = (entries + 511) / 512;
-    unsigned long pfn;
     struct desc_struct *vgdt;
 
     /* Check the new GDT. */
@@ -226,7 +239,7 @@ long set_gdt(struct domain *p,
     {
         if ( unlikely(frames[i] >= max_page) ||
              unlikely(!get_page_and_type(&frame_table[frames[i]], 
-                                         p, PGT_gdt_page)) )
+                                         d, PGT_gdt_page)) )
             goto fail;
     }
 
@@ -238,20 +251,15 @@ long set_gdt(struct domain *p,
     unmap_domain_mem(vgdt);
 
     /* Tear down the old GDT. */
-    for ( i = 0; i < 16; i++ )
-    {
-        if ( (pfn = l1_pgentry_to_pagenr(p->mm.perdomain_pt[i])) != 0 )
-            put_page_and_type(&frame_table[pfn]);
-        p->mm.perdomain_pt[i] = mk_l1_pgentry(0);
-    }
+    destroy_gdt(d);
 
     /* Install the new GDT. */
     for ( i = 0; i < nr_pages; i++ )
-        p->mm.perdomain_pt[i] =
+        d->mm.perdomain_pt[i] =
             mk_l1_pgentry((frames[i] << PAGE_SHIFT) | __PAGE_HYPERVISOR);
 
-    SET_GDT_ADDRESS(p, GDT_VIRT_START);
-    SET_GDT_ENTRIES(p, (entries*8)-1);
+    SET_GDT_ADDRESS(d, GDT_VIRT_START);
+    SET_GDT_ENTRIES(d, (entries*8)-1);
 
     return 0;
 
index fcec8991b2d06ac302d31dd14190a48a84c4bda4..3af08f07314d86bd7cb48ef73e5c761be558f60d 100644 (file)
@@ -17,7 +17,7 @@
 #include <asm/pdb.h>
 #include <xen/trace.h>
 #include <xen/console.h>
-#include <xen/shadow.h>
+#include <asm/shadow.h>
 #include <hypervisor-ifs/sched_ctl.h>
 
 #define TRC_DOM0OP_ENTER_BASE  0x00020000
index 3df97a7e25da558baf9afeeb837261346ddc362d..a2b83768cdb776475d0b02402d8e12825f863c4e 100644 (file)
@@ -1,3 +1,8 @@
+/******************************************************************************
+ * domain.c
+ * 
+ * Generic domain-handling functions.
+ */
 
 #include <xen/config.h>
 #include <xen/init.h>
@@ -8,8 +13,7 @@
 #include <xen/event.h>
 #include <xen/time.h>
 #include <xen/console.h>
-#include <xen/shadow.h>
-#include <xen/elf.h>
+#include <asm/shadow.h>
 #include <hypervisor-ifs/dom0_ops.h>
 #include <asm/hardirq.h>
 #include <asm/domain_page.h>
@@ -19,11 +23,6 @@ rwlock_t tasklist_lock __cacheline_aligned = RW_LOCK_UNLOCKED;
 struct domain *task_hash[TASK_HASH_SIZE];
 struct domain *task_list;
 
-extern void arch_do_createdomain(struct domain *);
-extern void arch_final_setup_guestos(struct domain *, full_execution_context_t *c);
-extern void free_perdomain_pt(struct domain *);
-extern void domain_relinquish_memory(struct domain *d);
-
 struct domain *do_createdomain(domid_t dom_id, unsigned int cpu)
 {
     char buf[100];
@@ -395,124 +394,7 @@ int final_setup_guestos(struct domain *p, dom0_builddomain_t *builddomain)
     set_bit(DF_CONSTRUCTED, &p->flags);
 
  out:    
-    if (c) kfree(c);
-    
+    if ( c != NULL )
+        kfree(c);
     return rc;
 }
-
-static inline int is_loadable_phdr(Elf_Phdr *phdr)
-{
-    return ((phdr->p_type == PT_LOAD) &&
-            ((phdr->p_flags & (PF_W|PF_X)) != 0));
-}
-
-int readelfimage_base_and_size(char *elfbase, 
-                                      unsigned long elfsize,
-                                      unsigned long *pkernstart,
-                                      unsigned long *pkernend,
-                                      unsigned long *pkernentry)
-{
-    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
-    Elf_Phdr *phdr;
-    Elf_Shdr *shdr;
-    unsigned long kernstart = ~0UL, kernend=0UL;
-    char *shstrtab, *guestinfo;
-    int h;
-
-    if ( !IS_ELF(*ehdr) )
-    {
-        printk("Kernel image does not have an ELF header.\n");
-        return -EINVAL;
-    }
-
-    if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
-    {
-        printk("ELF program headers extend beyond end of image.\n");
-        return -EINVAL;
-    }
-
-    if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize )
-    {
-        printk("ELF section headers extend beyond end of image.\n");
-        return -EINVAL;
-    }
-
-    /* Find the section-header strings table. */
-    if ( ehdr->e_shstrndx == SHN_UNDEF )
-    {
-        printk("ELF image has no section-header strings table (shstrtab).\n");
-        return -EINVAL;
-    }
-    shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + 
-                        (ehdr->e_shstrndx*ehdr->e_shentsize));
-    shstrtab = elfbase + shdr->sh_offset;
-    
-    /* Find the special '__xen_guest' section and check its contents. */
-    for ( h = 0; h < ehdr->e_shnum; h++ )
-    {
-        shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + (h*ehdr->e_shentsize));
-        if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 )
-            continue;
-        guestinfo = elfbase + shdr->sh_offset;
-        printk("Xen-ELF header found: '%s'\n", guestinfo);
-        if ( (strstr(guestinfo, "GUEST_OS=linux") == NULL) ||
-             (strstr(guestinfo, "XEN_VER=1.3") == NULL) )
-        {
-            printk("ERROR: Xen will only load Linux built for Xen v1.3\n");
-            return -EINVAL;
-        }
-        break;
-    }
-    if ( h == ehdr->e_shnum )
-    {
-        printk("Not a Xen-ELF image: '__xen_guest' section not found.\n");
-        return -EINVAL;
-    }
-
-    for ( h = 0; h < ehdr->e_phnum; h++ ) 
-    {
-        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
-        if ( !is_loadable_phdr(phdr) )
-            continue;
-        if ( phdr->p_vaddr < kernstart )
-            kernstart = phdr->p_vaddr;
-        if ( (phdr->p_vaddr + phdr->p_memsz) > kernend )
-            kernend = phdr->p_vaddr + phdr->p_memsz;
-    }
-
-    if ( (kernstart > kernend) || 
-         (ehdr->e_entry < kernstart) || 
-         (ehdr->e_entry > kernend) )
-    {
-        printk("Malformed ELF image.\n");
-        return -EINVAL;
-    }
-
-    *pkernstart = kernstart;
-    *pkernend   = kernend;
-    *pkernentry = ehdr->e_entry;
-
-    return 0;
-}
-
-int loadelfimage(char *elfbase)
-{
-    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
-    Elf_Phdr *phdr;
-    int h;
-  
-    for ( h = 0; h < ehdr->e_phnum; h++ ) 
-    {
-        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
-        if ( !is_loadable_phdr(phdr) )
-            continue;
-        if ( phdr->p_filesz != 0 )
-            memcpy((char *)phdr->p_vaddr, elfbase + phdr->p_offset, 
-                   phdr->p_filesz);
-        if ( phdr->p_memsz > phdr->p_filesz )
-            memset((char *)phdr->p_vaddr + phdr->p_filesz, 0, 
-                   phdr->p_memsz - phdr->p_filesz);
-    }
-
-    return 0;
-}
diff --git a/xen/common/elf.c b/xen/common/elf.c
new file mode 100644 (file)
index 0000000..72f1617
--- /dev/null
@@ -0,0 +1,128 @@
+/******************************************************************************
+ * elf.c
+ * 
+ * Generic Elf-loading routines.
+ */
+
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/mm.h>
+#include <xen/elf.h>
+
+static inline int is_loadable_phdr(Elf_Phdr *phdr)
+{
+    return ((phdr->p_type == PT_LOAD) &&
+            ((phdr->p_flags & (PF_W|PF_X)) != 0));
+}
+
+int readelfimage_base_and_size(char *elfbase, 
+                                      unsigned long elfsize,
+                                      unsigned long *pkernstart,
+                                      unsigned long *pkernend,
+                                      unsigned long *pkernentry)
+{
+    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
+    Elf_Phdr *phdr;
+    Elf_Shdr *shdr;
+    unsigned long kernstart = ~0UL, kernend=0UL;
+    char *shstrtab, *guestinfo;
+    int h;
+
+    if ( !IS_ELF(*ehdr) )
+    {
+        printk("Kernel image does not have an ELF header.\n");
+        return -EINVAL;
+    }
+
+    if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
+    {
+        printk("ELF program headers extend beyond end of image.\n");
+        return -EINVAL;
+    }
+
+    if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize )
+    {
+        printk("ELF section headers extend beyond end of image.\n");
+        return -EINVAL;
+    }
+
+    /* Find the section-header strings table. */
+    if ( ehdr->e_shstrndx == SHN_UNDEF )
+    {
+        printk("ELF image has no section-header strings table (shstrtab).\n");
+        return -EINVAL;
+    }
+    shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + 
+                        (ehdr->e_shstrndx*ehdr->e_shentsize));
+    shstrtab = elfbase + shdr->sh_offset;
+    
+    /* Find the special '__xen_guest' section and check its contents. */
+    for ( h = 0; h < ehdr->e_shnum; h++ )
+    {
+        shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + (h*ehdr->e_shentsize));
+        if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 )
+            continue;
+        guestinfo = elfbase + shdr->sh_offset;
+        printk("Xen-ELF header found: '%s'\n", guestinfo);
+        if ( (strstr(guestinfo, "GUEST_OS=linux") == NULL) ||
+             (strstr(guestinfo, "XEN_VER=1.3") == NULL) )
+        {
+            printk("ERROR: Xen will only load Linux built for Xen v1.3\n");
+            return -EINVAL;
+        }
+        break;
+    }
+    if ( h == ehdr->e_shnum )
+    {
+        printk("Not a Xen-ELF image: '__xen_guest' section not found.\n");
+        return -EINVAL;
+    }
+
+    for ( h = 0; h < ehdr->e_phnum; h++ ) 
+    {
+        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
+        if ( !is_loadable_phdr(phdr) )
+            continue;
+        if ( phdr->p_vaddr < kernstart )
+            kernstart = phdr->p_vaddr;
+        if ( (phdr->p_vaddr + phdr->p_memsz) > kernend )
+            kernend = phdr->p_vaddr + phdr->p_memsz;
+    }
+
+    if ( (kernstart > kernend) || 
+         (ehdr->e_entry < kernstart) || 
+         (ehdr->e_entry > kernend) )
+    {
+        printk("Malformed ELF image.\n");
+        return -EINVAL;
+    }
+
+    *pkernstart = kernstart;
+    *pkernend   = kernend;
+    *pkernentry = ehdr->e_entry;
+
+    return 0;
+}
+
+int loadelfimage(char *elfbase)
+{
+    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
+    Elf_Phdr *phdr;
+    int h;
+  
+    for ( h = 0; h < ehdr->e_phnum; h++ ) 
+    {
+        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
+        if ( !is_loadable_phdr(phdr) )
+            continue;
+        if ( phdr->p_filesz != 0 )
+            memcpy((char *)phdr->p_vaddr, elfbase + phdr->p_offset, 
+                   phdr->p_filesz);
+        if ( phdr->p_memsz > phdr->p_filesz )
+            memset((char *)phdr->p_vaddr + phdr->p_filesz, 0, 
+                   phdr->p_memsz - phdr->p_filesz);
+    }
+
+    return 0;
+}
index a2b06acc9dd7155ed30162c40d7588db3ba426af..2f99bbee434e5bf83877bd768e629ceeb497292a 100644 (file)
@@ -19,8 +19,8 @@
 #include <xen/compile.h>
 #include <xen/console.h>
 #include <xen/serial.h>
-#include <xen/shadow.h>
 #include <xen/trace.h>
+#include <asm/shadow.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <asm/domain_page.h>
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
new file mode 100644 (file)
index 0000000..e299f61
--- /dev/null
@@ -0,0 +1,17 @@
+
+#ifndef __ASM_X86_DOMAIN_H__
+#define __ASM_X86_DOMAIN_H__
+
+extern void arch_do_createdomain(struct domain *d);
+
+extern void arch_final_setup_guestos(
+    struct domain *d, full_execution_context_t *c);
+
+static inline void free_perdomain_pt(struct domain *d)
+{
+    free_page((unsigned long)d->mm.perdomain_pt);
+}
+
+extern void domain_relinquish_memory(struct domain *d);
+
+#endif /* __ASM_X86_DOMAIN_H__ */
index ffa8797fa95abc1c09c14964e7d472e6d262239a..0586562c626f06962bacc98c4e7691e49f0b2a93 100644 (file)
@@ -3,9 +3,6 @@
 #define __ASM_X86_MM_H__
 
 #include <xen/config.h>
-#ifdef LINUX_2_6
-#include <xen/gfp.h>
-#endif
 #include <xen/list.h>
 #include <xen/spinlock.h>
 #include <xen/perfc.h>
 
 #include <hypervisor-ifs/hypervisor-if.h>
 
-/*
- * The following is for page_alloc.c.
- */
-
-void init_page_allocator(unsigned long min, unsigned long max);
-unsigned long __get_free_pages(int order);
-void __free_pages(unsigned long p, int order);
-#define get_free_page()   (__get_free_pages(0))
-#define __get_free_page() (__get_free_pages(0))
-#define free_pages(_p,_o) (__free_pages(_p,_o))
-#define free_page(_p)     (__free_pages(_p,0))
-
-
 /*
  * Per-page-frame information.
  */
index bbd682e280be999222e3763acc6e0be83967cd13..11060e3c49dbc86de9d1276d116ee4d779fddc09 100644 (file)
@@ -406,7 +406,8 @@ static inline void write_ptbase(struct mm_struct *mm)
 #define GET_GDT_ENTRIES(_p)     ((*(u16 *)((_p)->mm.gdt + 0)))
 #define GET_GDT_ADDRESS(_p)     ((*(unsigned long *)((_p)->mm.gdt + 2)))
 
-long set_gdt(struct domain *p, 
+void destroy_gdt(struct domain *d);
+long set_gdt(struct domain *d, 
              unsigned long *frames, 
              unsigned int entries);
 
index df24329b2bea60760a37a680e1fe3d5b0eafaade..494a301220406c2d2475c4f28e97a7de019bdef0 100644 (file)
 #define shadow_linear_pg_table ((l1_pgentry_t *)SH_LINEAR_PT_VIRT_START)
 #define shadow_linear_l2_table ((l2_pgentry_t *)(SH_LINEAR_PT_VIRT_START+(SH_LINEAR_PT_VIRT_START>>(L2_PAGETABLE_SHIFT-L1_PAGETABLE_SHIFT))))
 
+#define shadow_mode(_d)      ((_d)->mm.shadow_mode)
+#define shadow_lock_init(_d) spin_lock_init(&(_d)->mm.shadow_lock)
+
 extern void shadow_mode_init(void);
-extern int shadow_mode_control( struct domain *p, dom0_shadow_control_t *sc );
-extern int shadow_fault( unsigned long va, long error_code );
-extern void shadow_l1_normal_pt_update( unsigned long pa, unsigned long gpte, 
-                                        unsigned long *prev_spfn_ptr,
-                                        l1_pgentry_t **prev_spl1e_ptr  );
-extern void shadow_l2_normal_pt_update( unsigned long pa, unsigned long gpte );
-extern void unshadow_table( unsigned long gpfn, unsigned int type );
-extern int shadow_mode_enable( struct domain *p, unsigned int mode );
-extern void shadow_mode_disable( struct domain *p );
+extern int shadow_mode_control(struct domain *p, dom0_shadow_control_t *sc);
+extern int shadow_fault(unsigned long va, long error_code);
+extern void shadow_l1_normal_pt_update(unsigned long pa, unsigned long gpte, 
+                                       unsigned long *prev_spfn_ptr,
+                                       l1_pgentry_t **prev_spl1e_ptr);
+extern void shadow_l2_normal_pt_update(unsigned long pa, unsigned long gpte);
+extern void unshadow_table(unsigned long gpfn, unsigned int type);
+extern int shadow_mode_enable(struct domain *p, unsigned int mode);
+
+extern void __shadow_mode_disable(struct domain *d);
+static inline void shadow_mode_disable(struct domain *d)
+{
+    if ( shadow_mode(d) )
+        __shadow_mode_disable(d);
+}
+
 extern unsigned long shadow_l2_table( 
     struct mm_struct *m, unsigned long gpfn );
 
@@ -75,11 +85,6 @@ printk("DOM%u: (file=shadow.c, line=%d) " _f "\n",    \
 #endif
 
 
-/************************************************************************/
-
-#define shadow_mode(d)         (d->mm.shadow_mode)
-#define        shadow_lock_init(d)     spin_lock_init(&d->mm.shadow_lock)
-
 /************************************************************************/
 
 static inline int __mark_dirty( struct mm_struct *m, unsigned int mfn )
@@ -100,14 +105,14 @@ static inline int __mark_dirty( struct mm_struct *m, unsigned int mfn )
     ASSERT(m->shadow_dirty_bitmap);
     if( likely(pfn<m->shadow_dirty_bitmap_size) )
     {
-       /* These updates occur with mm.shadow_lock held, so use 
-          (__) version of test_and_set */
-       if( __test_and_set_bit( pfn, m->shadow_dirty_bitmap ) == 0 )
-       {
-           // if we set it
-           m->shadow_dirty_count++;
-           rc = 1;
-       }
+        /* These updates occur with mm.shadow_lock held, so use 
+           (__) version of test_and_set */
+        if ( __test_and_set_bit( pfn, m->shadow_dirty_bitmap ) == 0 )
+        {
+            // if we set it
+            m->shadow_dirty_count++;
+            rc = 1;
+        }
     }
     else
     {
@@ -119,7 +124,7 @@ static inline int __mark_dirty( struct mm_struct *m, unsigned int mfn )
                frame_table[mfn].count_and_flags, 
                frame_table[mfn].type_and_flags );
     }
-       
+
     return rc;
 }
 
@@ -138,13 +143,13 @@ static inline int mark_dirty( struct mm_struct *m, unsigned int mfn )
 
 /************************************************************************/
 
-static inline void l1pte_write_fault( struct mm_struct *m, 
-                                      unsigned long *gpte_p, unsigned long *spte_p )
+static inline void l1pte_write_fault(
+    struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p)
 { 
     unsigned long gpte = *gpte_p;
     unsigned long spte = *spte_p;
 
-    switch( m->shadow_mode )
+    switch ( m->shadow_mode )
     {
     case SHM_test:
         spte = gpte;
@@ -164,13 +169,13 @@ static inline void l1pte_write_fault( struct mm_struct *m,
     *spte_p = spte;
 }
 
-static inline void l1pte_read_fault( struct mm_struct *m, 
-                                     unsigned long *gpte_p, unsigned long *spte_p )
+static inline void l1pte_read_fault(
+    struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p)
 { 
     unsigned long gpte = *gpte_p;
     unsigned long spte = *spte_p;
 
-    switch( m->shadow_mode )
+    switch ( m->shadow_mode )
     {
     case SHM_test:
         spte = gpte;
@@ -192,13 +197,13 @@ static inline void l1pte_read_fault( struct mm_struct *m,
     *spte_p = spte;
 }
 
-static inline void l1pte_no_fault( struct mm_struct *m, 
-                                   unsigned long *gpte_p, unsigned long *spte_p )
+static inline void l1pte_no_fault(
+    struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p)
 { 
     unsigned long gpte = *gpte_p;
     unsigned long spte = *spte_p;
 
-    switch( m->shadow_mode )
+    switch ( m->shadow_mode )
     {
     case SHM_test:
         spte = 0;
@@ -227,9 +232,11 @@ static inline void l1pte_no_fault( struct mm_struct *m,
     *spte_p = spte;
 }
 
-static inline void l2pde_general( struct mm_struct *m, 
-                                  unsigned long *gpde_p, unsigned long *spde_p,
-                                  unsigned long sl1pfn)
+static inline void l2pde_general(
+    struct mm_struct *m, 
+    unsigned long *gpde_p,
+    unsigned long *spde_p,
+    unsigned long sl1pfn)
 {
     unsigned long gpde = *gpde_p;
     unsigned long spde = *spde_p;
@@ -256,8 +263,6 @@ static inline void l2pde_general( struct mm_struct *m,
 
 /*********************************************************************/
 
-
-
 #if SHADOW_HASH_DEBUG
 static void shadow_audit(struct mm_struct *m, int print)
 {
index ecf6bbca975190a281ef021f491c8ccdabeb6902..c66aeb0d3dc33da5684433b6ef02433af770b913 100644 (file)
@@ -24,6 +24,9 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef __XEN_ELF_H__
+#define __XEN_ELF_H__
+
 typedef u8     Elf_Byte;
 
 typedef u32    Elf32_Addr;     /* Unsigned program address */
@@ -521,3 +524,8 @@ typedef struct {
 #define AuxInfo                Aux64Info
 #endif
 
+extern int loadelfimage(char *);
+extern int readelfimage_base_and_size(
+    char *, unsigned long, unsigned long *, unsigned long *, unsigned long *);
+
+#endif /* __XEN_ELF_H__ */
index 13cc33afcc8d0363755cb44eae7f1ca3ec1ddc2c..0ad445b32b612d5a42e5794a39af507f1ab1d3e8 100644 (file)
@@ -2,6 +2,15 @@
 #ifndef __XEN_MM_H__
 #define __XEN_MM_H__
 
+/* page_alloc.c */
+void init_page_allocator(unsigned long min, unsigned long max);
+unsigned long __get_free_pages(int order);
+void __free_pages(unsigned long p, int order);
+#define get_free_page()   (__get_free_pages(0))
+#define __get_free_page() (__get_free_pages(0))
+#define free_pages(_p,_o) (__free_pages(_p,_o))
+#define free_page(_p)     (__free_pages(_p,0))
+
 #include <asm/mm.h>
 
 #endif /* __XEN_MM_H__ */
index f8a9981a5d8757652c43cfc69015c023115e98e8..d75257bf7c2c3d17edd2707b1857057b9625822b 100644 (file)
@@ -295,4 +295,6 @@ static inline void domain_unpause_by_systemcontroller(struct domain *d)
 #define IS_PRIV(_d) (test_bit(DF_PRIVILEGED, &(_d)->flags))
 #define IS_CAPABLE_PHYSDEV(_d) (test_bit(DF_PHYSDEV, &(_d)->flags))
 
+#include <asm/domain.h>
+
 #endif /* __SCHED_H__ */
diff --git a/xen/include/xen/shadow.h b/xen/include/xen/shadow.h
deleted file mode 100644 (file)
index c59e02e..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include <asm/shadow.h>